package thisgame.model;

import java.util.Formatter;

public class Position {
	private int x, y;
	
	public Position(int x, int y) {
		this.x = x;
		this.y = y;
	}
	public Position(Position other) {
		this(other.x, other.y);
	}

	// getters/setters
	public void setX(int x) {
		this.x = x;
	}
	public int getX() {
		return x;
	}
	public void setY(int y) {
		this.y = y;
	}
	public int getY() {
		return y;
	}
	
	public void add(Position other) {
		x += other.x;
		y += other.y;
	}
	public void add(int dx, int dy) {
		x += dx;
		y += dy;
	}
	public void sub(Position other) {
		x -= other.x;
		y -= other.y;
	}
	public void sub(int dx, int dy) {
		x -= dx;
		y -= dy;
	}
	
	@Override
	public boolean equals(Object obj) {
		return obj instanceof Position
			&& getX() == ((Position)obj).getX()
			&& getY() == ((Position)obj).getY(); 
	}
	
	@Override
	public String toString() {
		return new Formatter().format("%d@%d", getX(), getY()).toString();
	}
}
